---
title: Automated deployment and replacement of Scoring Code in AzureML
description: Create a DataRobot-managed AzureML prediction environment to deploy and replace DataRobot Scoring Code in AzureML.
section_name: MLOps
maturity: premium

---

# Automated deployment and replacement of Scoring Code in AzureML {: #automated-deployment-and-replacement-of-scoring-code-in-azureml }

!!! info "Availability information"
    Automated deployment and replacement of Scoring Code in AzureML is a premium feature. Contact your DataRobot representative or administrator for information on enabling this feature.

    <b>Feature flag:</b> Enable the Automated Deployment and Replacement of Scoring Code in AzureML

Create a DataRobot-managed AzureML prediction environment to deploy DataRobot Scoring Code in AzureML. With DataRobot management enabled, the external AzureML deployment has access to MLOps features, including automatic Scoring Code replacement.

## Create an AzureML prediction environment {: #create-an-azure-prediction-environment }

To deploy a model in AzureML, you first create a custom AzureML prediction environment:

1. Click **Deployments** > **Prediction Environments** and then click **Add prediction environment**.

    ![](images/pred-env-3.png)

2. In the **Add prediction environment** dialog box, configure the prediction environment settings:

    ![](images/azure-pred-env-settings.png)

    * Enter a descriptive **Name** and an optional **Description** of the prediction environment.

    * Select **Azure** from the **Platform** drop-down list. The **Supported Model Formats** settings are automatically set to **DataRobot Scoring Code** and can't be changed, as this is the only model format supported by AzureML.

    * Enable the **Managed by DataRobot** setting to allow this prediction environment to automatically package and deploy DataRobot Scoring Code models through the Management Agent.

    * Select the related Azure Service Principal **Credentials**.

        ??? note "Azure Service Principal credentials required"
            DataRobot management of Scoring Code in AzureML requires existing Azure Service Principal **Credentials**. If you don't have existing credentials, the **Azure Service Principal credentials required** alert appears, directing you to **Go to Credentials** to [create Azure Service Principal credentials](stored-creds).

            ![](images/azure-create-connection-alert.png)

            To create the required credentials, for **Credential type**, select **Azure Service Principal**. Then, enter a **Client ID**, **Client Secret**, **Azure Tenant ID**, and a **Display name**. To validate and save the credentials, click **Save and sign in**.

            ![](images/azure-credentials.png)

            You can find these IDs and the display name on Azure's **App registrations** > **Overview** tab (1). You can generate secrets on the [**App registration > Certificates and secrets** tab](https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app#add-credentials){ target=_blank }(2):

            ![](images/get-azure-credentials.png)

3. Configure the **Azure Subscription**, **Azure Resource Group**, and **AzureML Workspace** fields accessible using the provided **Credentials**.

4. (Optional) If you want to connect to and retrieve data from Azure Event Hubs for monitoring, configure the **Event Hubs Namespace**, **Event Hubs Instance**, and **Managed Identities** fields. This requires valid **Credentials**, an **Azure Subscription ID**, and an **Azure Resource Group**.

5. (Optional) If you are using tags for governance and resource management in AzureML, click **Add AzureML tags** and then **+ Add new tag** to add the required tags to the prediction environment.

    ![](images/azure-tags.png)

6. After you configure the environment settings, click **Add environment**.

    The AzureML environment is now available from the **Prediction Environments** page.


## Deploy a model to the AzureML prediction environment {: #deploy-a-model-to-the-azure-prediction-environment }

Once you've created an AzureML prediction environment, you can deploy a model to it:

1. Click **Model Registry > Registered Models** and select the Scoring Code enabled registered model version you want to deploy to the AzureML prediction environment.

    ![](images/reg-select-deploy-model.png)

    !!! tip
        You can also deploy a model to your AzureML prediction environment from the **Deployments** > **Prediction Environments** tab by clicking **+ Add new deployment** in the prediction environment.

2. On any tab in the registered model version, click **Deploy**.

    ![](images/reg-deploy-model.png)

3. In the **Select Deployment Target** dialog box, under **Select deploy target**, click **AzureML**.

    ![](images/azure-deploy-target.png)

    !!! note
        If you can't click the AzureML deployment target, the selected model doesn't have Scoring Code available.

4. Under **Select prediction environment**, select the AzureML prediction environment you added, and then click **Confirm**.

5. [Configure the deployment](add-deploy-info) and, in the **Prediction History and Service Health** section, under **Endpoint**, click **+ Add endpoint**.

    ![](images/azure-add-endpoint.png)

6. In the **Select endpoint** dialog box, define an **Online** or **Batch** endpoint, depending on your expected workload, and then click **Next**.

    ![](images/azure-select-endpoint.png)

7. (Optional) Define additional **Environment key-value pairs** to provide extra parameters to the Azure deployment interface, then click **Confirm**.

8. Click **Deploy model**.

    While the deployment is **Launching**, you can monitor the status events on the **Service Health** tab in **Recent Activity > Agent Activity**:

    ![](images/agent-deploy-activity.png)


## Make predictions in AzureML {: #make-predictions-in-azureml }

After you deploy a model to an AzureML prediction environment, you can use the code snippet from the **Predictions > Portable Predictions** tab to score data in AzureML.

![](images/azureml-port-pred.png)

Before you run the code snippet, you must provide the required credentials in either of the following ways:  

* Export the Azure Service Principal’s secrets as environment variables locally before running the snippet:

    Environment variable  | Description
    ----------------------|--------------------------
    `AZURE_CLIENT_ID`     | The **Application ID** in the **App registration > Overview** tab.
    `AZURE_TENANT_ID`     | The **Directory ID** in the **App registration > Overview** tab.
    `AZURE_CLIENT_SECRET` | The secret token generated in the [**App registration > Certificates and secrets** tab](https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app#add-credentials){ target=_blank }.

* Install the [Azure CLI](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli){ target=_blank }, and run the `az login` command to allow the portable predictions snippet to use your personal Azure credentials.

!!! important
    Deployments to AzureML **Batch** and **Online** endpoints utilize different APIs than standard DataRobot deployments.

    * Online endpoints support JSON or CSV as input and outputs results to JSON.

    * Batch endpoints support CSV input and output the results to a CSV file.
